# 25. 分配土地

25

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

let lines = [];
let m = 0; n = 0;
let lineCount = 0;

rl.on('line', function(line) {
    if (lineCount === 0) {
        [m, n] = line.split(' ').map(Number);
    } else {
        lines.push(line.split(' ').map(Number));
        if (lines.length === m) {
            processLand(lines);
        }
    }
    lineCount++;
})

function processLand(land) {
    let minPos = [];
    let maxPos = [];
    let maxArea = 0;
    for(let i=0; i<m; i++) {
        for(let j=0; j<n; j++) {
            let num = land[i][j];
            if (num !== 0) {
                if (!minPos[num]) {
                    minPos[num] = [i, j];
                    maxPos[num] = [i, j];
                } else {
                    minPos[num] = [Math.min(minPos[num][0], i), Math.min(minPos[num][1], j)];
                    maxPos[num] = [Math.max(maxPos[num][0], i), Math.max(maxPos[num][1], j)]
                }
            }
        }
    }

    for(let num in minPos) {
        let area = (maxPos[num][0] - minPos[num][0] + 1) * (maxPos[num][1] - minPos[num][1] + 1);
        maxArea = Math.max(maxArea, area);
    }

    console.log(maxArea);
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49